<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-12-10
 * Time: 上午9:08
 */

namespace admin\modules\basedata\controllers;


use admin\modules\basedata\models\AreaSearch;
use common\members\wodrow\tools\Tree;
use common\models\db\Area;
use yii\web\Controller;

class DefaultController extends Controller
{
    public function actionJdAreaBak1()
    {
//        \Yii::$app->cache->delete(\Yii::$app->controller->route);
        $tree = \Yii::$app->cache->get(\Yii::$app->controller->route);
        if (!$tree){
            $jd_area = Area::find()->select(['id', 'fid', 'text'=>'name'])->where(['!=', 'fid', 0])->asArray()->all();
            $tree = Tree::list2tree($jd_area, Area::CHINA_AREA_ROOT, 'id', 'fid', 'nodes');
            \Yii::$app->cache->set(\Yii::$app->controller->route, $tree, 86400);
        }
        return $this->render('jd-area-bak1', ['tree' => $tree]);
    }

    public function actionJdArea()
    {
        $searchModel = new AreaSearch();
        $dataProvider = $searchModel->search(\Yii::$app->request->queryParams);

        return $this->render('jd-area', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
}